package cn.houserent.service.impl;

import cn.houserent.dao.UserDao;
import cn.houserent.entity.User;
import cn.houserent.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User login(String name, String password) {
        List<User> users = userDao.getUserByProperty("name", name);
        Iterator<User> iterator = users.iterator();
        if (iterator.hasNext()){
            User user = iterator.next();
            if (password.equals(user.getPassword())){
               return user;
            }
        }
        return null;
    }

    @Override
    public void addNewUser(User user) {
        this.userDao.save(user);
        int i = 3/0;
    }
}
